<?php

$sql = "
   CREATE  TABLE IF NOT EXISTS `parser` (
      `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
      `group_id` INT(10) UNSIGNED NOT NULL,
      `url` VARCHAR(255) NOT NULL ,
      `parser_name` VARCHAR(100) NOT NULL ,
      `parsing` TINYINT NOT NULL DEFAULT 0 ,
      `next_parsing` DATE NOT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = MyISAM CHARACTER SET=utf8;
";
$this->_db->get_results( $sql );

$sql = "
    CREATE  TABLE IF NOT EXISTS `parsed_news` (
      `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
      `parser_id` INT(10) UNSIGNED NOT NULL ,
      `item_id` INT UNSIGNED NOT NULL ,
      `url` VARCHAR(255) NOT NULL ,
      `title` VARCHAR(255) NOT NULL ,
      `add_date` DATETIME NOT NULL ,
      `next_parsing` DATE NOT NULL ,
      `need_parsing` TINYINT NOT NULL DEFAULT 1 ,
      `news_date` DATETIME NULL ,
      PRIMARY KEY (`id`) ,
      INDEX `fk_parsed_news_parser` (`parser_id` ASC) ,
      CONSTRAINT `fk_parsed_news_parser`
	FOREIGN KEY (`parser_id` )
	REFERENCES `parser`.`parser` (`id` )
	ON DELETE NO ACTION
	ON UPDATE NO ACTION)
    ENGINE = MyISAM CHARACTER SET=utf8;
";
$this->_db->get_results( $sql );

$sql = "
    CREATE  TABLE IF NOT EXISTS `parsed_comment` (
      `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
      `parser_id` INT(10) UNSIGNED NOT NULL ,
      `news_id` INT(10) UNSIGNED NOT NULL ,
      `item_id` INT(10) UNSIGNED NOT NULL ,
      `comment` TEXT NOT NULL ,
      `add_time` TIMESTAMP NOT NULL ,
      PRIMARY KEY (`id`) ,
      INDEX `fk_parsed_comment_parser1` (`parser_id` ASC) ,
      CONSTRAINT `fk_parsed_comment_parser1`
	FOREIGN KEY (`parser_id` )
	REFERENCES `parser`.`parser` (`id` )
	ON DELETE NO ACTION
	ON UPDATE NO ACTION)
    ENGINE = MyISAM CHARACTER SET=utf8;
";
$this->_db->get_results( $sql );